package com.handinfo.android.ui;

import java.io.DataInputStream;
import java.io.IOException;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.game.item.Item;
import com.handinfo.android.utils.Tools;

/**
 * 领奖
 * @author ding
 */
public class Prize {
	public String m_key = null;//领奖key
	public String m_name = null;//领奖名字
	public String m_desc = null;//领奖描述
	public long m_timer = 0;//倒计时
	public byte m_can_get = 0;//是否可以领取 0不可,1可以
	
	public byte[] m_money_type = null;//金钱类型
	public long[] m_money_value = null;//金钱数量
	
	public Item[] m_item_list = null;//领奖道具
	
	public Prize() {
		
	}
	
	public byte moneysize;
	public byte itemsize;
	public void recvPrize(DataInputStream dis) throws IOException {
		Tools.debugPrintln("领奖读取开始...");
		m_key = dis.readUTF();
		Tools.debugPrintln("key = " + m_key);
		
		m_name = dis.readUTF();
		Tools.debugPrintln("name = " + m_name);
		
		m_desc = dis.readUTF();
		Tools.debugPrintln("描述 = " + m_desc);
		
		m_timer = dis.readLong();
		Tools.debugPrintln("倒计时 = " + m_timer);
		m_timer = m_timer * DWGameManager.FRAME_PER_SECOND;
		
		m_can_get = dis.readByte();
		Tools.debugPrintln("是否能领取 = " + m_can_get);
		
		moneysize = dis.readByte();
		Tools.debugPrintln("金钱长度 = " + moneysize);
		
		if (moneysize > 0) {
			m_money_type = new byte[moneysize];
			m_money_value = new long[moneysize];
			for (byte i = 0; i < moneysize; i++) {
				m_money_type[i] = dis.readByte();
				Tools.debugPrintln("金钱" + i + "类型  = " + m_money_type[i]);
				m_money_value[i] = dis.readLong();
				Tools.debugPrintln("金钱" + i + "数量 = " + m_money_value[i]);
			}
		}
		
		itemsize = dis.readByte();
		Tools.debugPrintln("道具长度 = " + itemsize);
		
		if (itemsize > 0) {
			m_item_list = new Item[itemsize];
			for (byte i = 0; i < itemsize; i++) {
				Item item = new Item();
				item.m_key = dis.readUTF();
				Tools.debugPrintln("道具" + i + "key = " + item.m_key);
				item.m_name = dis.readUTF();
				Tools.debugPrintln("道具" + i + "name = " + item.m_name);
				item.m_iconId = dis.readShort();
				item.m_icon = IconManger.getInstance().getIcon(item.m_iconId);
				Tools.debugPrintln("道具" + i + "icon = " + item.m_iconId);
				item.m_num = dis.readInt();
				Tools.debugPrintln("道具" + i + "num = " + item.m_num);
				m_item_list[i]= item;
			}
		}
		Tools.debugPrintln("领奖读取结束...");
	}
	
	public long countDown() {
		if (--m_timer > 0) {
			return m_timer / DWGameManager.FRAME_PER_SECOND;
		}
		return 0;
	}
	
	
}
